import { Shop } from 'shop-model.js';
var shop = new Shop();  
Page({

  data: {
    type: ["全部", "充值", "赠送"],
    currentTpye: 0,
    page: 1,
    hiddenNomore: true,
    hiddenLoading: true,
    hiddenNullData: true,
    onLoading: false,
    nomore: false,
    listData:[
      
    ]
  },

  onLoad: function (options) {
    this.data.type = options.type ? options.type : '';
    this._getData();
  },

  _getData: function () {
    var that = this;
    var args = {
      type: this.data.type,
      page: this.data.page,
      num: 15,
      status: this.data.status
    }
    that.setData({
      hiddenLoading: false
    })
    shop.log(args, (res) => {
      if (that.data.page == 1) {
        that.data.items = [];
      }
      var items = res.items;
      var items = that.data.listData.concat(items);
      that.setData({
        listData: items
      })
      //隐藏正在加载中
      that.setData({
        hiddenLoading: true
      })
      if (items.length == 0) {
        //显示没有数据
        that.setData({
          hiddenNullData: false
        })
      }
      if (that.data.page >= res._meta.pageCount) {
        that.data.nomore = true;
        if (that.data.page > 1) {
          //显示没有更多
          that.setData({
            hiddenNomore: false
          })
        }
      }
    });
  },
  onReachBottom: function () {
    if (this.data.nomore) {
      return false;
    }
    this.data.page++;
    this._getData();
  },
  bindPickerChange: function (e) {
    this.setData({
      currentTpye: e.detail.value
    })
  },
})